from dataclasses import dataclass
from typing import Any, Union, List


@dataclass(frozen=True)
class JsonPatErrorWithPath(Exception):
    path: List[Union[str, int]]

    def _format_path(self):
        return "".join([f"[{c}]" if isinstance(c, int) else f".{c}" for c in self.path])


@dataclass(frozen=True)
class JsonVerificationError(JsonPatErrorWithPath):
    value: Any
    message: str

    def __str__(self):
        return self._format_path() + self.message


@dataclass(frozen=True)
class JsonPatClassError(JsonPatErrorWithPath):
    cls: Any

    def __str__(self):
        return self._format_path() + "为无法识别的类型声明" + str(self.cls)

